/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.doeacc.tms.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author slok
 */
@Entity
public class Shipment implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    private String shippingFrom;

    private String shippingTo;

    @Temporal(TemporalType.TIME)
    private Date shippingDate;

    @ManyToOne
    private Truck truck;

    @ManyToOne
    private Driver driver;

    @ManyToOne
    private User createdBy;
    
    @OneToMany
    private Set<ShippingInvoice> invoices = new HashSet<ShippingInvoice>();
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public User getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(User createdBy) {
        this.createdBy = createdBy;
    }

    public Driver getDriver() {
        return driver;
    }

    public void setDriver(Driver driver) {
        this.driver = driver;
    }

    public Set<ShippingInvoice> getInvoices() {
        return invoices;
    }

    public void setInvoices(Set<ShippingInvoice> invoices) {
        this.invoices = invoices;
    }

    public Date getShippingDate() {
        return shippingDate;
    }

    public void setShippingDate(Date shippingDate) {
        this.shippingDate = shippingDate;
    }

    public String getShippingFrom() {
        return shippingFrom;
    }

    public void setShippingFrom(String shippingFrom) {
        this.shippingFrom = shippingFrom;
    }

    public String getShippingTo() {
        return shippingTo;
    }

    public void setShippingTo(String shippingTo) {
        this.shippingTo = shippingTo;
    }

    public Truck getTruck() {
        return truck;
    }

    public void setTruck(Truck truck) {
        this.truck = truck;
    }

    public List<ShippingInvoiceItem> getAllShippingItems() {
        List<ShippingInvoiceItem> items = new ArrayList<ShippingInvoiceItem>();
        for(ShippingInvoice invoice: this.getInvoices()) {
            for(ShippingInvoiceItem item: invoice.getItems()) {
                items.add(item);
            }
        }
        return items;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Shipment)) {
            return false;
        }
        Shipment other = (Shipment) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    public String getType() {
        return "manifesto";
    }
    
    @Override
    public String toString() {
        return "edu.doeacc.tms.domain.Shipment[id=" + id + "]";
    }

}
